package org.rxc.gift.exception;



import cn.hutool.core.util.StrUtil;

import java.util.Collection;
import java.util.Objects;

/**
 * 断言工具类
 */
public class RonghuaAssert {
    //断言字符串为空,则字符串不为空抛出异常
    public static void isNotBlank(String str,String message){
        if (StrUtil.isBlank(str)){
            throw new BusinessException(message);
        }
    }
    //断言字符串不为空,则字符串为空抛出异常
    public static void isBlank(String str,String message){
        if (StrUtil.isNotBlank(str)){
            throw new BusinessException(message);
        }
    }
    //断言对象为空,则对象不为空抛出异常
    public static void isNull(Object obj,String message){
        if (Objects.nonNull(obj)){
            throw new BusinessException(message);
        }
    }
    //断言对象不为空,则对象为空抛出异常
    public static void isNotNull(Object obj,String message){
        if (Objects.isNull(obj)){
            throw new BusinessException(message);
        }
    }
    //断言集合为空,则集合不为空抛出异常
    public static void isNull(Collection collection, String message){
        if (collection != null&& collection.size()>0){
            throw new BusinessException(message);
        }
    }
    //断言集合不为空,则集合为空抛出异常
    public static void isNotNull(Collection collection,String message){
        if (collection == null || collection.size()==0){
            throw new BusinessException(message);
        }
    }
    //断言两个字符串值相等
    public static void isEq(String str1,String str2,String message){
        if (str1.equals(str2)){
            throw new BusinessException(message);
        }
    }

    //=====================code===============================

    //断言字符串为空,则字符串不为空抛出异常
    public static void isNotBlank(String str,ResponseCode responseCode){
        if (StrUtil.isBlank(str)){
            throw new BusinessException(responseCode);
        }
    }
    //断言字符串不为空,则字符串为空抛出异常
    public static void isBlank(String str,ResponseCode responseCode){
        if (StrUtil.isNotBlank(str)){
            throw new BusinessException(responseCode);
        }
    }
    //断言对象为空,则对象不为空抛出异常
    public static void isNull(Object obj,ResponseCode responseCode){
        if (Objects.nonNull(obj)){
            throw new BusinessException(responseCode);
        }
    }
    //断言对象不为空,则对象为空抛出异常
    public static void isNotNull(Object obj,ResponseCode responseCode){
        if (Objects.isNull(obj)){
            throw new BusinessException(responseCode);
        }
    }
    //断言集合为空,则集合不为空抛出异常
    public static void isNull(Collection collection,ResponseCode responseCode){
        if (collection != null&& collection.size()>0){
            throw new BusinessException(responseCode);
        }
    }
    //断言集合不为空,则集合为空抛出异常
    public static void isNotNull(Collection collection,ResponseCode responseCode){
        if (collection == null || collection.size()==0){
            throw new BusinessException(responseCode);
        }
    }
    //断言两个字符串值相等
    public static void isEq(String str1,String str2,ResponseCode responseCode){
        if (!str1.equals(str2)){
            throw new BusinessException(responseCode);
        }
    }

    public static void isEqIgnoreCase(String str1,String str2,ResponseCode responseCode){
        if (!str1.equalsIgnoreCase(str2)){
            throw new BusinessException(responseCode);
        }
    }

    public static void isTrue(Boolean flag,ResponseCode responseCode){
        if ((!flag)){
            throw new BusinessException(responseCode);
        }
    }
}
